# _*_ utf-8 _*_
__author__ = "LiuJian"
__date__ = "2021/7/22 0022 11:14"

# @FileName :register_login_quit.py

from pymysql import *

while True:
    conn = connect(user='user',
                   password="leboAa!#$123",
                   host='49.233.39.160',
                   database='lebo',
                   port=3306,
                   charset="utf8")
    cur = conn.cursor(cursor=cursors.DictCursor)
    try:
        inp = int(input('请输入1、登录系统   2、注册用户   3、退出系统     输入其他请重新输入'))
        if inp == 2:
            print("------------------------------------------------注册------------------------------------------------")
            uname = input('姓名：')
            uage = int(input('年龄：'))
            uheight = float(input('身高：'))
            sql = "select * from melon where uname = '%s' and uage = %d and uheight = %f"  % (uname, uage, uheight)
            print(sql)
            count = cur.execute(sql)
            print(count)
            if count >= 1:
                print("你输入的用户已注册，请重新输入！！！")
            else:
                sql = "insert into melon(uname, uage, uheight) values ('%s', %d, %f)" % (uname, uage, uheight)
                print(sql)
                cur.execute(sql)
                conn.commit()
                print("用户注册成功")
        elif inp == 1:
            print("------------------------------------------------登录------------------------------------------------")
            uname = input('姓名：')
            uage = int(input('年龄：'))
            uheight = float(input('身高：'))
            sql = "select * from melon where uname = '%s' and uage = %d and uheight = %f"  % (uname, uage, uheight)
            count = cur.execute(sql)
            if count >= 1:
                print('登录成功')
                sql = "select * from melon where uname = '%s' and uage = %d and uheight = %f"  % (uname, uage, uheight)
                ret = cur.fetchone()
                print(ret)
                break
            else:
                print('你输入的用户名、密码或身高不正确')
                continue
        elif inp == 3:
            print("------------------------------------------------退出------------------------------------------------")
            break
        else:
            print('你输入的数字不正确，请重新输入')
            continue
    except Exception as e:
        print('您输入的信息：%s不是数字类型，请重新输入'  % e)
        continue
    finally:
        cur.close()
        conn.close()